package nerdicide.experiments.reasoning;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;

public class Questions {
	
	private static int questionCount = 0;
	
	public static final MultipleChoiceQuestion loadQuestion(String questionFilePath) {
		questionCount++;
		Properties questionProperties = new Properties();
		try {
			questionProperties.load(new FileInputStream(questionFilePath));
			String scenario = questionProperties.getProperty("scenario");
			String question = questionProperties.getProperty("question");
			ArrayList<String> answerOptions = new ArrayList<String> ();
			String correctOption = questionProperties.getProperty("correctOption");
			answerOptions.add(questionProperties.getProperty("option1"));
			answerOptions.add(questionProperties.getProperty("option2"));
			answerOptions.add(questionProperties.getProperty("option3"));
			answerOptions.add(questionProperties.getProperty("option4"));
			answerOptions.add(questionProperties.getProperty("option5"));
			int abstractedNounsCount = Integer.valueOf(questionProperties.getProperty("abstractedNounCount"));
			int abstractedVerbsCount = Integer.valueOf(questionProperties.getProperty("abstractedVerbCount"));
			HashMap<String, String> plainNounMap = new HashMap<String, String> ();
			for(int i = 0; i < abstractedNounsCount; i++) { 
				String nounKey = "noun" + (i + 1);
				String enclosedNounKey = "<" + nounKey + ">";
				plainNounMap.put(enclosedNounKey, questionProperties.getProperty(nounKey));
			}
			HashMap<String, String> plainVerbMap = new HashMap<String, String> ();
			for(int i = 0; i < abstractedVerbsCount; i++) {
				String verbKey = "verb" + (i + 1);
				String enclosedVerbKey = "<" + verbKey + ">";
				plainVerbMap.put(enclosedVerbKey, questionProperties.getProperty(verbKey));
			}			
			return new MultipleChoiceQuestion(questionCount, scenario, question, correctOption, answerOptions, plainNounMap, plainVerbMap);
		} catch(IOException e) {
			System.out.println("Unable to load file " + questionFilePath + ": " + e.getMessage());
		}
		return null;
	}	
}
